home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / Programming / SPIM Folder / trap.handler < prev   
Encoding:
Text File  |  1992-11-30  |  3.1 KB  |  98 lines  |  [TEXT/ttxt]

  1. # SPIM S20 MIPS simulator.
  2. # The default trap handler for spim.
  3. # Copyright (C) 1990 James Larus, larus@cs.wisc.edu.
  4. #
  5. #
  6. # SPIM is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by the
  8. # Free Software Foundation; either version 1, or (at your option) any
  9. # later version.
  10. #
  11. # SPIM is distributed in the hope that it will be useful, but WITHOUT
  12. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14. # for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GNU CC; see the file COPYING.  If not, write to James R.
  18. # Larus, Computer Sciences Department, University of Wisconsin--Madison,
  19. # 1210 West Dayton Street, Madison, WI 53706, USA or to the Free
  20. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. # $Header: /var/home/cs354/.spim/RCS/trap.handler,v 2.2 1992/11/10 22:42:50 scottk Exp $
  23.  
  24.  
  25. # Define the exception handling code.  This must go first!
  26.  
  27.     .kdata
  28. __m1_:    .asciiz "  Exception "
  29. __m2_:    .asciiz " caught by trap handler.\n"
  30. __m3_:    .asciiz "Continuing. . .\n"
  31. __m4_:    .asciiz "Halting.\n"
  32. __e0_:    .asciiz " [Interrupt]"
  33. __e1_:    .asciiz    " [TLB modification !BUG!]"
  34. __e2_:    .asciiz    " [TLB miss !BUG!]"
  35. __e3_:    .asciiz    " [TLB miss !BUG!]"
  36. __e4_:    .asciiz    " [Unaligned address in inst/data fetch]"
  37. __e5_:    .asciiz    " [Unaligned address in store]"
  38. __e6_:    .asciiz    " [Bad address in text read]"
  39. __e7_:    .asciiz    " [Bad address in data/stack read]"
  40. __e8_:    .asciiz    " [Error in syscall]"
  41. __e9_:    .asciiz    " [Breakpoint]"
  42. __e10_:    .asciiz    " [Reserved instruction]"
  43. __e11_:    .asciiz    " [Syscall exception !BUG!]"
  44. __e12_:    .asciiz    " [Arithmetic overflow]"
  45. __e13_:    .asciiz    " [Inexact floating point result]"
  46. __e14_:    .asciiz    " [Invalid floating point result]"
  47. __e15_:    .asciiz    " [Divide by 0]"
  48. __e16_:    .asciiz    " [Floating point overflow]"
  49. __e17_:    .asciiz    " [Floating point underflow]"
  50. __excp:    .word __e0_,__e1_,__e2_,__e3_,__e4_,__e5_,__e6_,__e7_,__e8_,__e9_
  51.     .word __e10_,__e11_,__e12_,__e13_,__e14_,__e15_,__e16_,__e17_
  52. s1:    .word 0
  53. s2:    .word 0
  54.  
  55.     .ktext
  56.     .space 0x80    # Put trap handler at 0x8000080
  57.     sw $v0 s1    # Not re-entrent
  58.     sw $a0 s2    # Don't need to save k0/k1
  59.     mfc0 $k0 $13    # Cause
  60.     and $k0 $k0 0xff# Use just ExcCode field
  61.     mfc0 $k1 $14    # EPC
  62.     li $v0 4    # Print " Exception "
  63.     la $a0 __m1_
  64.     syscall
  65.     li $v0 1    # Print exception number
  66.         srl $a0 $k0 2
  67.     syscall
  68.     li $v0 4    # Print type of exception
  69.     lw $a0 __excp($k0)
  70.     syscall
  71.     li $v0 4    # Print " occurred.\n"
  72.     la $a0 __m2_
  73.     syscall
  74.         srl $a0 $k0 2
  75.     beq $a0 12 ret    # continue on overflow
  76.     beq $a0 13 ret    # continue on inexact fp result
  77.     beq $a0 14 ret    # continue on invalid fp result
  78.     beq $a0 16 ret    # continue on fp overflow
  79.     beq $a0 17 ret    # continue on fp underflow
  80.     li $v0 4    # Print "Halting.\n"
  81.     la $a0 __m4_
  82.     syscall
  83.     li $v0 10    # Exit on all bug overflow exceptions
  84.     syscall        # syscall 10 (exit)
  85.  
  86. ret:    li $v0 4    # Print "Continuing. . .\n"
  87.     la $a0 __m3_
  88.     syscall
  89.  
  90.     lw $v0 s1
  91.     lw $a0 s2
  92.     addiu $k1 $k1 4 # Return to next instruction
  93.     rfe        # Return from exception handler
  94.     jr $k1
  95.  
  96.     .text
  97.     .globl __start
  98.